#include <cstdio>
const int MaxN = 3e6 + 5;
int n;
long long Mod;
long long fact[MaxN];
long long fsp(long long x, long long y)
{
    long long res = 1;
    for (; y != 0;)
    {
        if (y & 1)
        {
            res *= x;
            res %= Mod;
        }
        y >>= 1;
        x *= x;
        x %= Mod;
    }
    return res;
}
long long inv(long long x)
{
    return fsp(x, Mod - 2);
}
long long A(long long x, long long y)
{
    return fact[x] * inv(fact[x - y]) % Mod;
}
long long C(long long x, long long y)
{
    return A(x, y) * inv(fact[y]) % Mod;
}
int main()
{
    freopen("tree.in", "r", stdin);
    freopen("tree.out", "w", stdout);
    scanf("%d%lld", &n, &Mod);
    long long answer = 0;
    fact[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        fact[i] = fact[i - 1] * i;
        fact[i] %= Mod;
    }
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        x = i;
        y = n - i;
        answer += A(n - 1, i - 1) * fsp(2, n - i) % Mod * fsp(y, y) % Mod;
        answer %= Mod;
    }
    printf("%lld\n", answer * n % Mod);
    return 0;
}